package com.puman.houmu.puman.Fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.puman.houmu.puman.Search.SearchActivity;
import com.puman.houmu.puman.utils.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import com.puman.houmu.puman.R;


/**
 * Created by layne on 2017/8/4.
 */

public class HomeFragment extends Fragment {
    private View view;
    private Banner banner;
    private List<String> imageUrl;
    private List<String> bannerTitle;

    private Button searchBtn;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container,false);
        initDate();
        initView();
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        searchBtn = (Button) view.findViewById(R.id.searchBtn);
        searchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(),"你大爷",Toast.LENGTH_SHORT).show();
                Intent searchIntent = new Intent();
                searchIntent.setClass(getActivity(), SearchActivity.class);
                startActivity(searchIntent);

            }
        });
    }




    private void initDate(){
        //图片地址
        imageUrl = new ArrayList<>();
        imageUrl.add("http://img02.tooopen.com/images/20140504/sy_60294738471.jpg");
        imageUrl.add("http://pic33.nipic.com/20130916/3420027_192919547000_2.jpg");
        imageUrl.add("http://img.taopic.com/uploads/allimg/121017/234940-12101FR22825.jpg");


        //Title名称
        bannerTitle = new ArrayList<>();
        bannerTitle.add("一");
        bannerTitle.add("二");
        bannerTitle.add("三");
    }

    private void initView(){
        banner = (Banner) view.findViewById(R.id.banner);
        banner.setBannerStyle(BannerConfig.NOT_INDICATOR);
        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(imageUrl);
        banner.setBannerTitles(bannerTitle);
        banner.setDelayTime(3000);
        banner.start();
    }

}















